/**
字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如，输入字符串"abcdefg"和数字2，该函数将返
回左旋转两位得到的结果"cdefgab"。 

 

 示例 1： 

 输入: s = "abcdefg", k = 2
输出: "cdefgab"
 

 示例 2： 

 输入: s = "lrloseumgh", k = 6
输出: "umghlrlose"
 

 

 限制： 

 
 1 <= k < s.length <= 10000 
 

 Related Topics 数学 双指针 字符串 👍 378 👎 0

*/

package com.shuzijun.leetcode.editor.cn;
public class ZuoXuanZhuanZiFuChuanLcof{
    public static void main(String[] args) {
         Solution solution = new ZuoXuanZhuanZiFuChuanLcof().new Solution();
         solution.reverseLeftWords("abcdefg",2);
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {

        public String reverseLeftWords(String s, int n) {
            char[] str = s.toCharArray();
            for (int i = 0; i < n; i++) {
                char tmp = str[0];
                for (int j = 1; j < str.length; j++) {
                    str[j-1] = str[j];
                }
                str[str.length-1] = tmp;
            }
            return new String(str);
        }
//    public String reverseLeftWords(String s, int n) {
//        char[] tmp = new char[s.length()];
//        for (int i = 0; i < n; i++) {
//            tmp[i+(s.length()-n)] = s.charAt(i);
//        }
//
//        for (int i = n; i < s.length(); i++) {
//            tmp[i-n] = s.charAt(i);
//        }
//
//        return new String(tmp);
//
//    }
}
//leetcode submit region end(Prohibit modification and deletion)

}